package com.aiti.lulian.controller.crad;

import cn.hutool.core.util.ReUtil;
import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.controller.LuLianDockingMeetingDetailsController;
import com.aiti.lulian.dto.CardBusinessQuotesDto;
import com.aiti.lulian.dto.CardQuoteListDto;
import com.aiti.lulian.entity.crad.CardInquiry;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.CardBusinessQuotesDto;
import com.aiti.lulian.entity.LuLianDockingMeetingDetails;
import com.aiti.lulian.entity.crad.CardBusinessQuotes;
import com.aiti.lulian.service.ICardBusinessQuotesService;
import com.aiti.lulian.vo.CardQuoteVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jsoup.helper.StringUtil;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("card_inquiry")
public class CardBusinessQuotesController extends WebController {

    protected final Logger logger = LoggerFactory.getLogger(CardBusinessQuotesController.class);

    private final ICardBusinessQuotesService cardBusinessQuotesService;


    public CardBusinessQuotesController(ICardBusinessQuotesService cardBusinessQuotesService) {
        this.cardBusinessQuotesService = cardBusinessQuotesService;
    }

    @GetMapping("/page")
    public Message page(CardQuoteVo quote){
        Page page = startPage();
        //quote.setUserId(findUserId());
        List<CardQuoteListDto> list = cardBusinessQuotesService.queryQuotePage(page, quote);
        return this.Success(this.getPageResult(list, (int)page.getTotal()));
    }

    @GetMapping("/detail")
    public Message detail(@RequestParam("baseId") String baseId){
        CardBusinessQuotesDto cardBusinessQuotesDto = cardBusinessQuotesService.quoteDetail(baseId);
        return this.Success(cardBusinessQuotesDto);
    }

    /**
     * 保存名片报价单
     * @param dto
     * @return
     */
    @PostMapping("/saveCardBusinessQuotes")
    public Message saveCardBusinessQuotes(@RequestBody CardBusinessQuotesDto dto) {
//        String clientId = dto.getClientId();
//        if(StringUtil.isBlank(clientId)){
//            return Message.fail("请选择客户");
//        }
        String userId = dto.getBaseCreateBy();
        if(StringUtil.isBlank(userId)){
            logger.error("保存名片报价单；没有找到用户Id");
            return Message.fail("没有找到用户Id");
        }
        cardBusinessQuotesService.saveCardBusinessQuotes(dto,userId);
        return Message.success();
    }

    /**
     * 修改询价单
     * @param dto
     * @return
     */
    @PutMapping("/updateQuotesById")
    public Message updateQuotesById(@RequestBody CardBusinessQuotesDto dto) {
        if(StringUtil.isBlank(dto.getBaseId())){
            return Message.fail("没有找到Id");
        }
        String userId = findUserId();
        cardBusinessQuotesService.updateQuotesById(dto,userId);
        return Message.success();
    }

    /**
     * 删除报价单
     * @param dto
     * @return
     */
    @DeleteMapping("/deleteQuotesById")
    public Message deleteQuotesById(@RequestBody CardBusinessQuotesDto dto) {
        if(StringUtil.isBlank(dto.getBaseId())){
            return Message.fail("没有找到主键");
        }
        cardBusinessQuotesService.deleteQuotesById(dto);
        return Message.success();
    }
}
